package com.gzbugu.bugusys.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.gzbugu.bugusys.bean.PageModel;
import com.gzbugu.bugusys.dao.IBaseDAO;
import com.gzbugu.bugusys.service.impl.FindTravelService;
import com.gzbugu.bugusys.vo.Travel;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Bokchoy 根据特定条件进行查找
 */
@Controller
public class FindTravelAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	@Resource(name = "baseDAO")
	private IBaseDAO baseDAO;
	@Resource(name = "findTravelService")
	private FindTravelService findTravelService;
	private Date travelStart;
	private Date travelEnd;
	private String staffId = "";
	private Integer year;
	private Integer month;
	private PageModel pageModel;
	private List<Travel> travelList;

	@SuppressWarnings("unchecked")
	public String execute() {
		if (staffId.equals("") && year.equals("")) {
			return INPUT;
		}
		// 校验PageModel，防止pageModel为空
		if (pageModel == null) {
			pageModel = new PageModel();
			pageModel.setPageSize(10);
		}
		findTravelService.setPageModel(pageModel);
		if (!staffId.equals("") && year != 0 && month !=0) {
			travelList = findTravelService.findTravelByMonthAndId(staffId,
					year, month);
		} else if (!staffId.equals("")) {
			if (!staffId.equals("")) {
				travelList = findTravelService.findTravelByStaffId(staffId);
			}
		} else if (year != 0 && month !=0) {
			travelList = findTravelService.findTravelByMonth(year, month);
		}
		return SUCCESS;
	}

	public void validate() {
		if (!staffId.equals("")) {
			if (baseDAO.findById(staffId,
					com.gzbugu.bugusys.fields.VoClasseFields.STAFF) == null) {
				this.addActionError("员工号:" + staffId + "不存在");
			}
		}
	}

	public PageModel getPageModel() {
		return pageModel;
	}

	public void setPageModel(PageModel pageModel) {
		this.pageModel = pageModel;
	}

	public String getStaffId() {
		return staffId;
	}

	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}

	public Date getTravelStart() {
		return travelStart;
	}

	public void setTravelStart(Date travelStart) {
		this.travelStart = travelStart;
	}

	public Date getTravelEnd() {
		return travelEnd;
	}

	public void setTravelEnd(Date travelEnd) {
		this.travelEnd = travelEnd;
	}

	public List<Travel> getTravelList() {
		return travelList;
	}

	public void setTravelList(List<Travel> travelList) {
		this.travelList = travelList;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public Integer getMonth() {
		return month;
	}

	public void setMonth(Integer month) {
		this.month = month;
	}

}
